<template>
  <div class="personal">
    <router-link :to="{ path: `/edit_profile/${userinfo.id}` }">
      <div class="profile">
        <!-- $axios.defaults.baseURL读取axios的服务器路径 -->
        <img
          :src="userinfo.head_img"
          alt
        />
        <div class="profile-center">
          <div class="name">
            <span class="iconfont iconxingbienan"></span>{{ userinfo.nickname }}
          </div>
          <div class="time">{{ userinfo.create_date | dataFormat }}</div>
        </div>
        <span class="iconfont iconjiantou1"></span>
      </div>
    </router-link>
    <mycell
      title="我的关注"
      desc="关注的用户"
      @click="$router.push({name:'myfollows'})"
    ></mycell>
    <mycell
      title="我的跟帖"
      desc="跟帖/回复"
    ></mycell>
    <mycell
      title="我的收藏"
      desc="文章/视频"
      @click="$router.push({name:'mystars'})"
    ></mycell>
    <mycell title="设置"></mycell>
    <mybutton
      type="error"
      @click="exit"
    >退出登录</mybutton>
  </div>
</template>

<script>
import mycell from "@/components/mycell.vue";
import mybutton from "@/components/mybutton.vue";
import { getUserByid } from "@/apis/user.js";
import { dataFormat } from "@/utils/myfilters.js";
import axios from "@/utils/myaxios.js";
export default {
  data() {
    return {
      userinfo: {},
    };
  },
  components: {
    mycell,
    mybutton,
  },
  methods: {
    exit() {
      localStorage.removeItem("hm_toutiao");
      localStorage.removeItem("hm_toutiao_userId");
      this.$router.push({ name: "index" });
    },
  },
  async mounted() {
    let res = await getUserByid(this.$route.params.id);
    this.userinfo = res.data.data;
    if (this.userinfo.head_img) {
      this.userinfo.head_img = axios.defaults.baseURL + this.userinfo.head_img;
    } else {
      this.userinfo.head_img =
        axios.defaults.baseURL + "/uploads/image/IMG1568705287936.jpeg";
    }
  },
  filters: {
    dataFormat,
  },
};
</script>

<style lang="less" scoped>
.personal {
  width: 100vw;
  height: 100vh;
  background-color: #eee;
}
a {
  color: #666;
}
.profile {
  display: flex;
  padding: 20px 10px;
  justify-content: space-between;
  align-items: center;
  border-bottom: 5px #ddd solid;

  img {
    width: 70 / 360 * 100vw;
    height: 70 / 360 * 100vw;
    border-radius: 50%;
  }

  .profile-center {
    flex: 1;
    padding: 0 10px;
  }

  .name {
    span {
      color: #75b9eb;
    }
  }

  .time {
    color: #666;
    font-size: 14px;
    margin-top: 5px;
  }
}
.btn {
  margin: 20px auto;
  background-color: #f00;
}
</style>
